import com.system.Requestmap
import com.system.RoleInfo
import com.system.UserInfo
import com.system.UserRole

class BootStrap {

    def init = { servletContext ->

        //创建允许所有访问的公共资源
        for (String url in [
                '/error', '/index', '/index.gsp', '/**/favicon.ico', '/shutdown',
                '/**/js/**', '/**/css/**', '/**/images/**',
                '/login', '/login.*', '/login/*',
                '/logout', '/logout.*', '/logout/*', '/assets/**']) {
            if(!Requestmap.findByUrl(url)){
                new Requestmap(url:url,configAttribute: "permitAll").save()
            }

        }

        //建立默认用户权限
        def superadminRoleInfo = new RoleInfo('ROLE_SUPERADMIN', '超级管理员').save()
        def adminRoleInfo = new RoleInfo('ROLE_ADMIN', '管理员').save()
        def userRoleInfo = new RoleInfo('ROLE_USER', '用户').save()


        def superUser = new UserInfo('sys', 'sys9988').save()
        UserRole.create superUser, superadminRoleInfo, true

        def user = new UserInfo('admin', 'admin9988').save()
        UserRole.create user, adminRoleInfo, true

        def testUser = new UserInfo('tom', 'tom9988').save()
        UserRole.create testUser, userRoleInfo, true
    }

    def destroy = {

    }
}
